package com.cennavi.buss.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.cennavi.buss.service.imp.IUploadService;
import com.cennavi.minemap.bean.MessageBean;

@RestController
@RequestMapping("/service/upload")
public class UploadController {

	@Autowired
	private IUploadService iUploadService;

	@RequestMapping(method = RequestMethod.POST, value = "/file", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean upload(@RequestParam("name") String name, @RequestParam("type") int type,
			@RequestParam("userId") int userId, @RequestParam("describe") String describe,
			@RequestParam("file") MultipartFile file) {
		return iUploadService.upload(name, type, userId, describe, file);
	}

	@RequestMapping(method = RequestMethod.GET, value = "/{id}", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean queryById(@PathVariable int id) {
		return iUploadService.queryById(id);
	}

	@RequestMapping(method = RequestMethod.GET, value = "/list/{userId}", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean queryByUserId(@PathVariable int userId) {
		return iUploadService.queryByUserId(userId);
	}

	@RequestMapping(method = RequestMethod.GET, value = "/create/{id}/{uploadId}", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean createTable(@PathVariable int id, @PathVariable int uploadId) {
		return iUploadService.createTable(id, uploadId);
	}

	@RequestMapping(method = RequestMethod.GET, value = "/test/{id}", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean test(@PathVariable int id) {
		return iUploadService.test(id);
	}

	@RequestMapping(method = RequestMethod.POST, value = "/detail/update/{userId}/{uploadId}", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean update(@PathVariable int userId, @PathVariable int uploadId,
			@RequestBody String json) {
		return iUploadService.update(userId, uploadId, json);
	}

	@RequestMapping(method = RequestMethod.GET, value = "/detail/list/{userId}/{uploadId}", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean queryUploadDetailList(@PathVariable Integer userId,
			@PathVariable Integer uploadId) {
		return iUploadService.queryUploadDetailList(userId, uploadId);
	}

	@RequestMapping(method = RequestMethod.GET, value = "/detail/byid/{userId}/{uploadId}/{id}", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean queryUploadDetailById(@PathVariable Integer userId, @PathVariable Integer uploadId,
			@PathVariable Integer id) {
		return iUploadService.queryUploadDetailById(userId, uploadId, id);
	}

	@RequestMapping(method = RequestMethod.GET, value = "/getSolu/{uploadId}", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean querySoluId(@PathVariable Integer uploadId) {
		return iUploadService.querySoluId(uploadId);
	}

	@RequestMapping(method = RequestMethod.POST, value = "/setSolu", produces = "application/json;charset=UTF-8")
	public @ResponseBody MessageBean saveSoluId(@RequestBody String text) {
		return iUploadService.saveSoluId(text);
	}
}
